<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>

  <body>
    <script src="../node_modules/@vue/reactivity/dist/reactivity.global.js"></script>
    <div id="app"></div>
    <div id="app1"></div>
    <script>
      let { reactive, effect, toRef, toRefs } = VueReactivity;
      let state = reactive({ name: "hulei" });
      // 对象直接解析会失去响应式
      let { name } = state;

      // 通过toRef会通过get、set代理的方式去访问原对象上的属性，不会失去响应式的特性
      let userName = toRef(state, "name");

      // 让对象每一个key，对应一个toRef
      console.log(toRefs(state));

      effect(() => {
        app.innerHTML = name;
      });

      effect(() => {
        app1.innerHTML = userName.value;
      });
      setTimeout(() => {
        name = "hu.lei";
        userName.value = "hu.lei";
      }, 3000);
    </script>
  </body>
</html>
